package com.example.administrator.xxnapp.fragment.tucao;

import android.content.Context;
import android.media.Image;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.administrator.xxnapp.R;
import com.example.administrator.xxnapp.bean.ImageBean;
import com.example.administrator.xxnapp.http.HttpUrl;

import java.util.List;

/**
 * Created by Administrator on 2018/5/6.
 */

public class RVTuCaoImageShowAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<ImageBean> mDatas;

    public RVTuCaoImageShowAdapter(Context context, List<ImageBean> mDatas) {
        this.context = context;
        this.mDatas = mDatas;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new RVImageViewHolder(LayoutInflater.from(context).inflate(R.layout.item_tucao_image_show_layout,parent,false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof RVImageViewHolder){
            ((RVImageViewHolder) holder).bindViews(position);
        }
    }

    @Override
    public int getItemCount() {
        return mDatas == null?0:mDatas.size();
    }

    private class RVImageViewHolder extends RecyclerView.ViewHolder{
        private ImageView mIV;

        public RVImageViewHolder(View itemView) {
            super(itemView);
            mIV = itemView.findViewById(R.id.item_tucao_iamge_show_layout_IV);
        }

        private void bindViews(int position){
            ImageBean bean = mDatas.get(position);
            Log.e("TAG", "bindViews: "+HttpUrl.BASE_URL_BASE+bean.getPath() );
            Glide.with(context).load(HttpUrl.BASE_URL_BASE+bean.getPath()).into(mIV);
        }
    }
}
